package io.renren.modules.vastFinance.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.vastFinance.entity.CreditEntity;
import io.renren.modules.vastFinance.service.CreditService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 授信服务表
 *
 * @author syh
 * @email sunlightcs@gmail.com
 * @date 2022-05-19 09:40:52
 */
@RestController
@RequestMapping("crud/credit")
public class CreditController {
    @Autowired
    private CreditService creditService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("crud:credit:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = creditService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{creditId}")
    @RequiresPermissions("crud:credit:info")
    public R info(@PathVariable("creditId") Integer creditId){
		CreditEntity credit = creditService.getById(creditId);

        return R.ok().put("credit", credit);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("crud:credit:save")
    public R save(@RequestBody CreditEntity credit){
		creditService.save(credit);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("crud:credit:update")
    public R update(@RequestBody CreditEntity credit){
		creditService.updateById(credit);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("crud:credit:delete")
    public R delete(@RequestBody Integer[] creditIds){
		creditService.removeByIds(Arrays.asList(creditIds));

        return R.ok();
    }

}
